import axios from '@ohos/axios'
import Invoice from '../viewModel/Invoice'
// let baseUrl= '10.2.2.108'
let baseUrl= '192.168.43.254'
class InvoiceModel{
  //查询
  getBudgetList():Promise<Invoice[]>{
    return new Promise((resolve,reject)=>{
      axios({
        method:'GET',
        // url:'http://localhost:8080/invoice/listInvoice',
        url:'http://'+baseUrl+':8080/invoice/listInvoice',
        params:{
          uid:AppStorage.Get('uid')
        },
        headers:{
          'Content-Type': 'application/json',
          'token':AppStorage.Get('token')
        }
      }).then(resp=>{
        if (resp.status == 200) {
          console.log('success',JSON.stringify(resp.data))
          resolve(resp.data)
        }
        else console.log('失败')
        reject('查询失败')
      })
    })
  }
  //删除
  deleteRecord(invoice:Invoice):Promise<number>{
    return new Promise((resolve,reject)=>{
      axios({
        method:'POST',
        // url:'http://localhost:8080/invoice/deleteInvoice',
        url:'http://'+baseUrl+':8080/invoice/deleteInvoice',
        data:{
          uid:AppStorage.Get('uid'),
          iid:invoice.iid,
          iname:invoice.iname,
          address:invoice.address,
          duty:invoice.duty,
          bank:invoice.bank,
          bankid:invoice.bankid,
          isdelete:invoice.isdelete
        },
        headers:{
          'Content-Type': 'application/json',
          'token':AppStorage.Get('token')
        }
      }).then(resp=>{
        if (resp.status == 200) {
          console.log('success',JSON.stringify(resp.data))
          resolve(resp.data)
        }
        else console.log('失败')
        reject('失败')
      })
    })
  }
  //新增
  insertBudget(invoice:Invoice):Promise<number>{
    return new Promise((resolve,reject)=>{
      axios({
        method:'POST',
        // url:'http://localhost:8080/invoice/insertInvoice',
        url:'http://'+baseUrl+':8080/invoice/insertInvoice',
        data:{
          uid:AppStorage.Get('uid'),
          iname:invoice.iname,
          address:invoice.address,
          duty:invoice.duty,
          bank:invoice.bank,
          bankid:invoice.bankid,
          isdelete:0
        },
        headers:{
          'Content-Type': 'application/json',
          'token':AppStorage.Get('token')
        }
      }).then(resp=>{
        if (resp.status == 200) {
          console.log('success',JSON.stringify(resp.data))
          resolve(resp.data)
        }
        else console.log('失败')
        reject('失败')
      })
    })
  }

  //修改
  updateRecord(invoice:Invoice):Promise<number>{
    return new Promise((resolve,reject)=>{
      axios({
        method:'POST',
        // url:'http://localhost:8080/invoice/updateInvoice',
        url:'http://'+baseUrl+':8080/invoice/updateInvoice',
        data:{
          uid:AppStorage.Get('uid'),
          iid:invoice.iid,
          iname:invoice.iname,
          address:invoice.address,
          duty:invoice.duty,
          bank:invoice.bank,
          bankid:invoice.bankid,
          isdelete:invoice.isdelete
        },
        headers:{
          'Content-Type': 'application/json',
          'token':AppStorage.Get('token')
        }
      }).then(resp=>{
        if (resp.status == 200) {
          console.log('success',JSON.stringify(resp.data))
          resolve(resp.data)
        }
        else console.log('失败')
        reject('失败')
      })
    })
  }


}
const invoiceModel = new InvoiceModel();
export default invoiceModel as InvoiceModel;


